import { _ as _export_sfc, x as useMainStore, y as storeToRefs, z as ref, al as useNavbarHeight, B as onLoad, c as createBlock, w as withCtx, n as normalizeStyle, H as unref, i as index$g, j as resolveEasycom, k as resolveDynamicComponent, o as openBlock, b as createVNode, t as createTextVNode, ae as Input, u as toDisplayString, f as normalizeClass, Q as index$x, au as chooseLocation, ag as navigateBack } from './index-Cc4oxzDN.js';
import { _ as __easycom_2 } from './list-cell.BHNnBKKp.js';
import { g as getAddressAddAndEdit } from './address.47BWBG0i.js';

const _sfc_main = {
  __name: 'add',
  setup(__props) {

const main = useMainStore();
const { isLogin,addresses } = storeToRefs(main);
ref('编辑地址');

// 获取导航栏高度
const { navbarHeightCss } = useNavbarHeight();

const form = ref({
	realName: '',
	isDefault: 0,
	phone: '',
	address: '',
	detail: '',
	latitude: '',
	longitude: ''
});

onLoad((option) => {
	//为了方便演示，这里用本地缓存
	console.log('option:',option);
	if (option.id) {
		form.value = addresses.value.find(item => item.id == option.id);
	}
});

const save = async() => {
	let data = {};
	if (form.value.hasOwnProperty('id')) {
		data = await getAddressAddAndEdit(form.value);
	} else {
		data = await getAddressAddAndEdit(form.value);
	}
	if (data) {
		setTimeout(function(){
			navigateBack();
		}, 2000);
	}
};

const chooseLocation$1 = async() => {
	chooseLocation({
		success: function (res) {
			form.value.address = res.address + ' ' + res.name;
			form.value.latitude = res.latitude;
			form.value.longitude = res.longitude;
		}
	});
	// let [error, res] = await uni.chooseLocation();
	// if (res) {
	// 	form.value.address = res.address + ' ' + res.name;
	// 	form.value.latitude = res.latitude;
	// 	form.value.longitude = res.longitude;
	// }
};


return (_ctx, _cache) => {
  const _component_v_uni_view = index$g;
  const _component_v_uni_input = Input;
  const _component_list_cell = resolveEasycom(resolveDynamicComponent("list-cell"), __easycom_2);
  const _component_v_uni_button = index$x;

  return (openBlock(), createBlock(_component_v_uni_view, {
    class: "container",
    style: normalizeStyle(`padding-top: ${unref(navbarHeightCss)};`)
  }, {
    default: withCtx(() => [
      createVNode(_component_v_uni_view, { class: "form-box" }, {
        default: withCtx(() => [
          createVNode(_component_v_uni_view, { class: "form" }, {
            default: withCtx(() => [
              createVNode(_component_list_cell, { hover: false }, {
                default: withCtx(() => [
                  createVNode(_component_v_uni_view, { class: "form-input" }, {
                    default: withCtx(() => [
                      createVNode(_component_v_uni_view, { class: "label" }, {
                        default: withCtx(() => [
                          createTextVNode("收货人")
                        ]),
                        _: 1
                      }),
                      createVNode(_component_v_uni_input, {
                        class: "input",
                        placeholder: "请输入收货人",
                        modelValue: form.value.realName,
                        "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => ((form.value.realName) = $event)),
                        "placeholder-class": "text-color-assist"
                      }, null, 8, ["modelValue"])
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }),
              createVNode(_component_list_cell, { hover: false }, {
                default: withCtx(() => [
                  createVNode(_component_v_uni_view, { class: "form-input" }, {
                    default: withCtx(() => [
                      createVNode(_component_v_uni_view, { class: "label" }, {
                        default: withCtx(() => [
                          createTextVNode("联系方式")
                        ]),
                        _: 1
                      }),
                      createVNode(_component_v_uni_input, {
                        class: "input",
                        placeholder: "请输入收货人联系方式",
                        modelValue: form.value.phone,
                        "onUpdate:modelValue": _cache[1] || (_cache[1] = $event => ((form.value.phone) = $event)),
                        "placeholder-class": "text-color-assist"
                      }, null, 8, ["modelValue"])
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }),
              createVNode(_component_list_cell, { hover: false }, {
                default: withCtx(() => [
                  createVNode(_component_v_uni_view, { class: "form-input" }, {
                    default: withCtx(() => [
                      createVNode(_component_v_uni_view, { class: "label" }, {
                        default: withCtx(() => [
                          createTextVNode("收货地址")
                        ]),
                        _: 1
                      }),
                      createVNode(_component_v_uni_view, {
                        class: "input",
                        onClick: chooseLocation$1
                      }, {
                        default: withCtx(() => [
                          createTextVNode(toDisplayString(form.value.address ? form.value.address : '请选择收货地址'), 1)
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }),
              createVNode(_component_list_cell, { hover: false }, {
                default: withCtx(() => [
                  createVNode(_component_v_uni_view, { class: "form-input" }, {
                    default: withCtx(() => [
                      createVNode(_component_v_uni_view, { class: "label" }, {
                        default: withCtx(() => [
                          createTextVNode("详细地址")
                        ]),
                        _: 1
                      }),
                      createVNode(_component_v_uni_input, {
                        class: "input",
                        placeholder: "请输入收货人详细地址",
                        modelValue: form.value.detail,
                        "onUpdate:modelValue": _cache[2] || (_cache[2] = $event => ((form.value.detail) = $event)),
                        "placeholder-class": "text-color-assist"
                      }, null, 8, ["modelValue"])
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }),
              createVNode(_component_list_cell, { hover: false }, {
                default: withCtx(() => [
                  createVNode(_component_v_uni_view, { class: "form-input" }, {
                    default: withCtx(() => [
                      createVNode(_component_v_uni_view, { class: "label" }, {
                        default: withCtx(() => [
                          createTextVNode("默认地址")
                        ]),
                        _: 1
                      }),
                      createVNode(_component_v_uni_view, { class: "radio-group" }, {
                        default: withCtx(() => [
                          createVNode(_component_v_uni_view, {
                            class: normalizeClass(["radio", {'checked': !form.value.isDefault}]),
                            style: {"margin-right":"10rpx"},
                            onClick: _cache[3] || (_cache[3] = $event => (form.value.isDefault=0))
                          }, {
                            default: withCtx(() => [
                              createTextVNode("否")
                            ]),
                            _: 1
                          }, 8, ["class"]),
                          createVNode(_component_v_uni_view, {
                            class: normalizeClass(["radio", {'checked': form.value.isDefault}]),
                            onClick: _cache[4] || (_cache[4] = $event => (form.value.isDefault=1))
                          }, {
                            default: withCtx(() => [
                              createTextVNode("是")
                            ]),
                            _: 1
                          }, 8, ["class"])
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              })
            ]),
            _: 1
          }),
          createVNode(_component_v_uni_view, { class: "btn-section" }, {
            default: withCtx(() => [
              createVNode(_component_v_uni_button, {
                type: "primary",
                size: "default",
                onClick: save
              }, {
                default: withCtx(() => [
                  createTextVNode("保存")
                ]),
                _: 1
              })
            ]),
            _: 1
          })
        ]),
        _: 1
      })
    ]),
    _: 1
  }, 8, ["style"]))
}
}

};
const add = /*#__PURE__*/_export_sfc(_sfc_main, [['__scopeId',"data-v-d035c181"]]);

export { add as default };
